﻿(function() {
	if (window.ymPrompt) return;
	var objType = function($) {
			return new Function("o", "return Object.prototype.toString.call(o)=='[object " + $ + "]'")
		},
		isArray = objType("Array"),
		isObj = objType("Object");
	window.ymPrompt = {
		version: "4.0",
		pubDate: "2009-03-02",
		apply: function(B, _, $) {
			if ($) ymPrompt.apply(B, $);
			if (B && _ && isObj(_)) for (var A in _) B[A] = _[A];
			return B
		},
		eventList: []
	};
	var initFn = ["setDefaultCfg", "show"],
		_initFn = {},
		t;
	while (t = initFn.shift()) ymPrompt[t] = eval("0,function(){_initFn." + t + "?_initFn." + t + ".push(arguments):(_initFn." + t + "=[arguments])}");
	var isIE = !+"\v1",
		isCompat = document.compatMode == "CSS1Compat",
		IE6 = isIE && /MSIE (\d)\./.test(navigator.userAgent) && parseInt(RegExp.$1) < 7,
		useFixed = !isIE || (!IE6 && isCompat),
		$ = function($) {
			return document.getElementById($)
		},
		$height = function($) {
			return parseInt($.style.height) || $.offsetHeight
		},
		addEvent = (function() {
			return new Function("env", "fn", "obj", "obj=obj||document;" + (window.attachEvent ? "obj.attachEvent('on'+env,fn)" : "obj.addEventListener(env,fn,false)") + ";ymPrompt.eventList.push([env,fn,obj])")
		})(),
		detachEvent = (function() {
			return new Function("env", "fn", "obj", "obj=obj||document;" + (window.attachEvent ? "obj.detachEvent('on'+env,fn)" : "obj.removeEventListener(env,fn,false)"))
		})(),
		setStyle = function(A, B, $) {
			if (!A) return;
			if (isObj(B)) {
				for (var C in B) setStyle(A, C, B[C]);
				return
			}
			if (isArray(A) || /htmlcollection|nodelist/i.test("" + A)) {
				for (C = A.length - 1; C >= 0; C--) setStyle(A[C], B, $);
				return
			}
			try {
				A.style[B] = $
			} catch (_) {}
		},
		btnIndex = 0,
		btnCache, seed = 0,
		mkBtn = function(E, _, D, $) {
			if (!E) return;
			if (isArray(E)) {
				var B, A = [],
					C = {
						OK: [curCfg.okTxt, "ok"],
						CANCEL: [curCfg.cancelTxt, "cancel"]
					};
				while (E.length)(B = E.shift()) && A[A.push(mkBtn.apply(null, C[B] || B)) - 1] || A.pop();
				return A
			}
			$ = $ || "ymPrompt_btn_" + seed++;
			D = D == undefined ? "undefined" : !! D;
			return {
				id: $,
				html: "<input type='button' id='" + $ + "' onclick='ymPrompt.doHandler(\"" + _ + "\"," + D + ")' style='cursor:pointer' class='btnStyle handler' value='" + E + "' />"
			}
		},
		joinBtn = function($) {
			if (!$) return btnCache = "";
			if (!isArray($)) $ = [$];
			if (!$.length) return btnCache = "";
			btnCache = $.concat();
			var _ = [];
			while ($.length) _.push($.shift().html);
			return _.join("&nbsp;&nbsp;")
		},
		dftCfg = {
			message: "内容",
			width: 300,
			height: 185,
			title: "标题",
			handler: function() {},
			maskAlphaColor: "#000",
			maskAlpha: 0.1,
			iframe: false,
			icoCls: "",
			btn: null,
			autoClose: true,
			fixPosition: true,
			dragOut: false,
			titleBar: true,
			showMask: false,
			winPos: "c",
			winAlpha: 0.8,
			closeBtn: true,
			showShadow: false,
			useSlide: false,
			slideCfg: {
				increment: 0.3,
				interval: 50
			},
			closeTxt: "关闭",
			okTxt: " 确 定 ",
			cancelTxt: " 取 消 ",
			msgCls: "ym-content",
			minBtn: false,
			minTxt: "最小化",
			maxBtn: false,
			maxTxt: "最大化",
			allowSelect: false,
			allowRightMenu: false
		},
		curCfg = {};
	(function() {
		var rootEl = document.body,
			callee = arguments.callee;
		if (!rootEl || typeof rootEl != "object") return addEvent("load", callee, window);
		if (isIE && document.readyState != "complete") return addEvent("readystatechange", function() {
			document.readyState == "complete" && callee()
		});
		rootEl = isCompat ? document.documentElement : rootEl;
		var frameset = document.getElementsByTagName("frameset").length;
		if (!isIE && frameset) return;
		var getScrollPos = function() {
				return curCfg.fixPosition && useFixed ? [0, 0] : [rootEl.scrollLeft, rootEl.scrollTop]
			},
			saveWinInfo = function() {
				var $ = getScrollPos();
				ymPrompt.apply(dragVar, {
					_offX: parseInt(ym_win.style.left) - $[0],
					_offY: parseInt(ym_win.style.top) - $[1]
				})
			},
			maskStyle = "position:absolute;top:0;left:0;display:none;text-align:center",
			div = document.createElement("div");
		div.innerHTML = ["<div id='maskLevel' style='" + maskStyle + ";z-index:10000;'></div>", IE6 ? ("<iframe id='maskIframe' src='javascript:false' style='" + maskStyle + ";z-index:9999;filter:alpha(opacity=0);opacity:0'></iframe>") : "", "<div id='ym-window' style='position:absolute;z-index:10001;display:none'>", IE6 ? "<iframe src='javascript:false' style='width:100%;height:100%;position:absolute;top:0;left:0;z-index:-1'></iframe>" : "", "<div class='ym-tl' id='ym-tl'><div class='ym-tr'><div class='ym-tc' style='cursor:move;'><div class='ym-header-text'></div><div class='ym-header-tools'>", "<div class='ymPrompt_min' title='最小化'><strong>0</strong></div>", "<div class='ymPrompt_max' title='最大化'><strong>1</strong></div>", "<div class='ymPrompt_close' title='关闭'><strong>r</strong></div>", "</div></div></div></div>", "<div class='ym-ml' id='ym-ml'><div class='ym-mr'><div class='ym-mc'><div class='ym-body' style='position:relative'></div></div></div></div>", "<div class='ym-ml' id='ym-btnl'><div class='ym-mr'><div class='ym-btn'></div></div></div>", "<div class='ym-bl' id='ym-bl'><div class='ym-br'><div class='ym-bc'></div></div></div>", "</div>", isIE ? "<div id='ym-shadow' style='position:absolute;z-index:10000;background:#808080;filter:alpha(opacity=80) progid:DXImageTransform.Microsoft.Blur(pixelradius=2);display:none'></div>" : ""].join("");
		document.body.appendChild(div);
		var maskLevel = $("maskLevel"),
			ym_win = $("ym-window"),
			ym_shadow = $("ym-shadow"),
			ym_wins, ym_headbox = $("ym-tl"),
			ym_head = ym_headbox.firstChild.firstChild,
			ym_hText = ym_head.firstChild,
			ym_hTool = ym_hText.nextSibling,
			ym_body = $("ym-ml").firstChild.firstChild.firstChild,
			ym_btn = $("ym-btnl"),
			ym_btnContent = ym_btn.firstChild.firstChild,
			ym_bottom = $("ym-bl"),
			maskEl = [maskLevel];
		IE6 && maskEl.push($("maskIframe"));
		var ym_ico = ym_hTool.childNodes,
			dragVar = {},
			cur_state = "normal",
			cur_cord = [0, 0],
			cal_cord = function() {
				var $ = getScrollPos();
				cur_cord = [parseInt(ym_win.style.left) - $[0], parseInt(ym_win.style.top) - $[1]]
			},
			doMax = function() {
				cal_cord();
				cur_state = "max";
				ym_ico[1].firstChild.innerHTML = "2";
				ym_ico[1].className = "ymPrompt_normal";
				setWinSize(rootEl.clientWidth, rootEl.clientHeight, [0, 0])
			},
			doMin = function() {
				cal_cord();
				cur_state = "min";
				ym_ico[0].firstChild.innerHTML = "2";
				ym_ico[0].className = "ymPrompt_normal";
				setWinSize(0, $height(ym_headbox), cur_cord)
			},
			doNormal = function($) {
				!$ && cur_state == "min" && cal_cord();
				cur_state = "normal";
				ym_ico[0].firstChild.innerHTML = "0";
				ym_ico[1].firstChild.innerHTML = "1";
				ym_ico[0].className = "ymPrompt_min";
				ym_ico[1].className = "ymPrompt_max";
				setWinSize.apply(this, $ ? [] : [0, 0, cur_cord])
			},
			max, min;
		addEvent("click", min = function() {
			cur_state != "normal" ? doNormal() : doMin()
		}, ym_ico[0]);
		addEvent("click", max = function() {
			cur_state != "normal" ? doNormal() : doMax()
		}, ym_ico[1]);
		addEvent("dblclick", function($) {
			curCfg.maxBtn && ($.srcElement || $.target).parentNode != ym_hTool && max()
		}, ym_head);
		addEvent("click", function() {
			ymPrompt.doHandler("close")
		}, ym_ico[2]);
		var getWinSize = function() {
				return [Math.max(rootEl.scrollWidth, rootEl.clientWidth), Math.max(rootEl.scrollHeight, rootEl.clientHeight)]
			},
			winSize = getWinSize(),
			bindEl = ym_head.setCapture && ym_head,
			filterWin = function($) {
				!frameset && setStyle(ym_win, $ == 1 && isCompat ? {
					filter: "",
					opacity: ""
				} : {
					filter: "Alpha(opacity=" + $ * 100 + ")",
					opacity: $
				})
			},
			mEvent = function(A) {
				var _ = dragVar.offX + A.clientX,
					C = dragVar.offY + A.clientY;
				if (!curCfg.dragOut) {
					var D = getScrollPos(),
						$ = D[0],
						B = D[1];
					_ = Math.min(Math.max(_, $), rootEl.clientWidth - ym_win.offsetWidth + $);
					C = Math.min(Math.max(C, B), rootEl.clientHeight - ym_win.offsetHeight + B)
				} else if (curCfg.showMask && "" + winSize != "" + getWinSize()) resizeMask(true);
				setStyle(ym_wins, {
					left: _ + "px",
					top: C + "px"
				})
			},
			uEvent = function() {
				filterWin(1);
				detachEvent("mousemove", mEvent, bindEl);
				detachEvent("mouseup", uEvent, bindEl);
				saveWinInfo();
				curCfg.iframe && setStyle(getPage().nextSibling, "display", "none");
				bindEl && (detachEvent("losecapture", uEvent, bindEl), bindEl.releaseCapture())
			};
		addEvent("mousedown", function(_) {
			if ((_.srcElement || _.target).parentNode == ym_hTool) return false;
			filterWin(curCfg.winAlpha);
			ymPrompt.apply(dragVar, {
				offX: parseInt(ym_win.style.left) - _.clientX,
				offY: parseInt(ym_win.style.top) - _.clientY
			});
			addEvent("mousemove", mEvent, bindEl);
			addEvent("mouseup", uEvent, bindEl);
			if (curCfg.iframe) {
				var A = {
					display: ""
				},
					$ = getPage();
				isCompat && IE6 && ymPrompt.apply(A, {
					width: $.offsetWidth,
					height: $.offsetHeight
				});
				setStyle($.nextSibling, A)
			}
			bindEl && (addEvent("losecapture", uEvent, bindEl), bindEl.setCapture())
		}, ym_head);
		var scrollEvent = function() {
				setStyle(ym_win, {
					left: dragVar._offX + rootEl.scrollLeft + "px",
					top: dragVar._offY + rootEl.scrollTop + "px"
				})
			},
			keydownEvent = function(A) {
				var _ = A.keyCode;
				if (_ == 27) destroy();
				if (btnCache) {
					var C = btnCache.length,
						B;
					document.activeElement && document.activeElement.id != btnCache[btnIndex].id && (B = true);
					if (_ == 9 || _ == 39) B && (btnIndex = -1), $(btnCache[++btnIndex == C ? (--btnIndex) : btnIndex].id).focus();
					if (_ == 37) B && (btnIndex = C), $(btnCache[--btnIndex < 0 ? (++btnIndex) : btnIndex].id).focus();
					if (_ == 13) return true
				}
				return keyEvent(A, (_ > 110 && _ < 123) || _ == 9 || _ == 13)
			},
			keyEvent = function(A, _) {
				A = A || event;
				if (!_ && /input|select|textarea/i.test((A.srcElement || A.target).tagName)) return true;
				try {
					A.returnValue = false;
					A.keyCode = 0
				} catch ($) {
					A.preventDefault && A.preventDefault()
				}
				return false
			};
		maskLevel.oncontextmenu = keyEvent;
		var resizeMask = function($) {
				setStyle(maskEl, "display", "none");
				var A = getWinSize(),
					_ = function() {
						setStyle(maskEl, {
							width: A[0] + "px",
							height: A[1] + "px",
							display: ""
						})
					};
				isIE ? $ === true ? _() : setTimeout(_, 0) : _();
				cur_state == "min" ? doMin() : cur_state == "max" ? doMax() : setWinSize()
			},
			maskVisible = function($) {
				if (!curCfg.showMask) return;
				($ === false ? detachEvent : addEvent)("resize", resizeMask, window);
				if ($ === false) return setStyle(maskEl, "display", "none");
				setStyle(maskLevel, {
					background: curCfg.maskAlphaColor,
					filter: "Alpha(opacity=" + curCfg.maskAlpha * 100 + ")",
					opacity: curCfg.maskAlpha
				});
				resizeMask(true)
			},
			getPos = function(f) {
				f = isArray(f) && f.length == 2 ? (f[0] + "+{2},{3}+" + f[1]) : (posMap[f] || posMap["c"]);
				var pos = [rootEl.clientWidth - ym_win.offsetWidth, rootEl.clientHeight - ym_win.offsetHeight].concat(getScrollPos()),
					arr = f.replace(/\{(\d)\}/g, function(_, $) {
						return pos[$]
					}).split(",");
				return [eval(arr[0]), eval(arr[1])]
			},
			posMap = {
				c: "{0}/2+{2},{1}/2+{3}",
				l: "{2},{1}/2+{3}",
				r: "{0}+{2},{1}/2+{3}",
				t: "{0}/2+{2},{3}",
				b: "{0}/2,{1}+{3}",
				lt: "{2},{3}",
				lb: "{2},{1}+{3}",
				rb: "{0}+{2},{1}+{3}",
				rt: "{0}+{2},{3}"
			},
			setWinSize = function($, _, A) {
				if (ym_win.style.display == "none") return;
				_ = parseInt(_) || curCfg.height;
				$ = parseInt($) || curCfg.width;
				setStyle(ym_wins, {
					width: $ + "px",
					height: _ + "px",
					left: 0,
					top: 0
				});
				A = getPos(A || curCfg.winPos);
				setStyle(ym_wins, {
					top: A[1] + "px",
					left: A[0] + "px"
				});
				saveWinInfo();
				setStyle(ym_body, "height", _ - $height(ym_headbox) - $height(ym_btn) - $height(ym_bottom) + "px");
				isCompat && IE6 && curCfg.iframe && setStyle(getPage(), {
					height: ym_body.clientHeight
				})
			},
			_obj = [],
			cacheWin = [],
			winVisible = function(A) {
				var F = A === false ? detachEvent : addEvent;
				F("scroll", curCfg.fixPosition && !useFixed ? scrollEvent : saveWinInfo, window);
				setStyle(ym_wins, "position", curCfg.fixPosition && useFixed ? "fixed" : "absolute");
				F("keydown", keydownEvent);
				if (A === false) {
					setStyle(ym_shadow, "display", "none");
					var C = function() {
							setStyle(ym_win, "display", "none");
							setStyle(_obj, "visibility", "visible");
							_obj = [];
							cacheWin.shift();
							if (cacheWin.length) ymPrompt.show.apply(null, cacheWin[0].concat(true))
						},
						_ = function() {
							var A = 1,
								_ = function() {
									A = Math.max(A - curCfg.slideCfg.increment, 0);
									filterWin(A);
									if (A == 0) {
										maskVisible(false);
										C();
										clearInterval($)
									}
								};
							_();
							var $ = setInterval(_, curCfg.slideCfg.interval)
						};
					curCfg.useSlide ? _() : C();
					return
				}
				for (var D = document.getElementsByTagName("object"), G = D.length - 1; G > -1; G--) D[G].style.visibility != "hidden" && _obj.push(D[G]) && (D[G].style.visibility = "hidden");
				setStyle([ym_hText, ym_hTool], "display", (curCfg.titleBar ? "" : "none"));
				ym_head.className = "ym-tc" + (curCfg.titleBar ? "" : " ym-ttc");
				ym_hText.innerHTML = curCfg.title;
				for (var G = 0, B = ["min", "max", "close"]; G < 3; G++) {
					ym_ico[G].style.display = curCfg[B[G] + "Btn"] ? "" : "none";
					ym_ico[G].title = curCfg[B[G] + "Txt"]
				}
				var E = "position:absolute;width:100%;height:100%;top:0;left:0;opacity:1;filter:alpha(opacity=100)";
				ym_body.innerHTML = !curCfg.iframe ? ("<div class=\"" + curCfg.msgCls + "\">" + curCfg.message + "</div>") : "<iframe style='" + E + "' border='0' frameborder='0' src='" + curCfg.message + "'></iframe><div style='" + E + ";background:#000;opacity:0.1;filter:alpha(opacity=10);display:none'></div>";
				(function(_, A) {
					for (var B in A) {
						try {
							_[B] = A[B]
						} catch ($) {}
					}
				})(ym_body.firstChild, curCfg.iframe);
				ym_body.className = "ym-body " + curCfg.icoCls;
				setStyle(ym_btn, "display", ((ym_btnContent.innerHTML = joinBtn(mkBtn(curCfg.btn))) ? "" : "none"));
				!curCfg.useSlide && curCfg.showShadow && setStyle(ym_shadow, "display", "");
				setStyle(ym_win, "display", "");
				doNormal(true);
				filterWin(curCfg.useSlide ? 0 : 1);
				curCfg.useSlide && (function() {
					var A = 0,
						$ = function() {
							A = Math.min(A + curCfg.slideCfg.increment, 1);
							filterWin(A);
							if (A == 1) {
								clearInterval(_);
								curCfg.showShadow && setStyle(ym_shadow, "display", "")
							}
						};
					$();
					var _ = setInterval($, curCfg.slideCfg.interval)
				})();
				btnCache && $(btnCache[btnIndex = 0].id).focus();
				ym_win.onselectstart = curCfg.allowSelect ? null : keyEvent;
				ym_win.oncontextmenu = curCfg.allowRightMenu ? null : keyEvent
			},
			init = function() {
				ym_wins = [ym_win].concat(curCfg.showShadow ? ym_shadow : "");
				maskVisible();
				winVisible()
			},
			destroy = function() {
				!curCfg.useSlide && maskVisible(false);
				winVisible(false)
			},
			getPage = function() {
				return curCfg.iframe ? ym_body.firstChild : null
			};
		ymPrompt.apply(ymPrompt, {
			close: destroy,
			max: max,
			min: min,
			normal: doNormal,
			getPage: getPage,
			show: function(_, $, C) {
				if (!C && cacheWin.push([_, $]) && cacheWin.length > 1) return;
				var A = [].slice.call(_, 0),
					B = {},
					D = -1;
				if (!isObj(A[0])) {
					for (var E in dftCfg) if (A[++D]) B[E] = A[D]
				} else B = A[0];
				ymPrompt.apply(curCfg, ymPrompt.apply({}, B, $), ymPrompt.setDefaultCfg());
				for (E in curCfg) curCfg[E] = curCfg[E] != null ? curCfg[E] : ymPrompt.cfg[E];
				init()
			},
			doHandler: function($, B, A) {
				if (B == undefined ? curCfg.autoClose : B) destroy();
				try {
					(curCfg.handler)($)
				} catch (_) {
					alert(_.message)
				}
			},
			resizeWin: setWinSize,
			setDefaultCfg: function($) {
				return ymPrompt.cfg = ymPrompt.apply({}, $, ymPrompt.apply({}, ymPrompt.cfg, dftCfg))
			},
			getButtons: function() {
				var A = btnCache || [],
					_, B = [];
				while (_ = A.shift()) B.push($(_.id));
				return B
			}
		});
		ymPrompt.setDefaultCfg();
		var t;
		for (var i in _initFn) while (t = _initFn[i].shift()) ymPrompt[i].apply(null, t);
		addEvent("unload", function() {
			while (ymPrompt.eventList.length) detachEvent.apply(null, ymPrompt.eventList.shift())
		}, window)
	})()
})();
ymPrompt.apply(ymPrompt, {
	alert: function() {
		ymPrompt.show(arguments, {
			icoCls: "ymPrompt_alert",
			btn: ["OK"]
		})
	},
	succeedInfo: function() {
		ymPrompt.show(arguments, {
			icoCls: "ymPrompt_succeed",
			btn: ["OK"]
		})
	},
	errorInfo: function() {
		ymPrompt.show(arguments, {
			icoCls: "ymPrompt_error",
			btn: ["OK"]
		})
	},
	confirmInfo: function() {
		ymPrompt.show(arguments, {
			icoCls: "ymPrompt_confirm",
			btn: ["OK", "CANCEL"]
		})
	},
	win: function() {
		ymPrompt.show(arguments)
	}
})